/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.Model.Repositories;

import com.Model.Acervo;
import com.thoughtworks.xstream.XStream;
import java.util.List;

/**
 *
 * @author Fellipe
 */
public class AcervoRepository {

    private com.Clientes.Acervo.Acervo_Service service = new com.Clientes.Acervo.Acervo_Service();
    private com.Clientes.Acervo.Acervo port = service.getAcervoPort();
    private XStream xstream = new XStream();

//Clientes WEB    
    public void create(Acervo a) {
        System.out.println(toXML(a));
        port.create(toXML(a));
        System.out.println("PRONTO!");
    }
    
    public List<Acervo> readNomes() {
        return fromXMLList(port.readNomes());
    }

    public Acervo read(int chaveAcervo) {
        return fromXML(port.read(chaveAcervo));
    }

    public void update(Acervo a) {
        port.update(toXML(a));
    }

    public void delete(int cod) {
        //port.delete(cod);
        System.out.println("Deletou acervo " + cod);
    }
    
    public List<Acervo> buscaNome(String busca) {
        return fromXMLList(port.buscaNome(busca));
    }
 
//Funções XML
    private String toXML(Acervo a) {
        return xstream.toXML(a);
    }

    private List<Acervo> fromXMLList(String xml) {
        return (List<Acervo>) xstream.fromXML(xml);
    }
    
    private Acervo fromXML(String xml) {
        return (Acervo) xstream.fromXML(xml);
    }
    
}
